using ExampleWebApplication.Entities;
using NHibernate.Mapping.ByCode;
using NHibernate.Mapping.ByCode.Conformist;

namespace ExampleWebApplication.Infraestruture.NHibernate.EntityMappings
{
    public class TerritoryMap : ClassMapping<Territory>
    {
        public TerritoryMap()
        {
            Table("Territories");
            Id(x => x.TerritoryID, map => { map.Generator(Generators.Assigned); map.Column("TerritoryID"); });
            Property(x => x.TerritoryDescription, map => { map.Column("TerritoryDescription"); map.NotNullable(true); map.Length(50); });
            ManyToOne(x => x.Region, map => map.Column("RegionID"));
            Bag(x => x.EmployeeTerritories, map => { map.Inverse(true); map.Key(key => key.Column("TerritoryID")); }, rel => rel.OneToMany());
        }
    }
}
